import java.io.IOException;
import java.io.PipedInputStream;

//向管道流读数据的线程
public class Receiver extends Thread {
    private PipedInputStream in;
    public Receiver(Sender sender) throws IOException {
        in=new PipedInputStream(sender.getPipedOutputStream());

    }

    public void run() {


            try {
                int data;
                while((data=in.read())!=-1)
                    System.out.print((char) data);
                in.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

    }

    public static void main(String[] args) throws IOException {
            Sender sender=new Sender();
            Receiver receiver=new Receiver(sender);
            sender.start();
            receiver.start();

    }
}
